/**
 * FileName: MyConfig
 * Author:   xing.yang@vcg.com
 * Date:     2020/6/2 14:43
 * Description:
 */
package com.vcg.vdam.config;

import com.vcg.vdam.annotation.YangxingScanAnnotation;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Configuration
@EnableConfigurationProperties(Users.class)
@Import({MyConfig2.class,TestImportBeanDefinitionRegistrar.class})

public class MyConfig1 {

    private final Users users;

    public MyConfig1(Users users) {
        this.users = users;
    }

    //直接通过bean注解注入
//    @Bean
//    public  Classes findClasses(){
//        Classes classes = new Classes();
//        classes.setNumber(Integer.parseInt(users.getAge()));
//        return classes;
//    }

    //直接通过判断当前类是否已经注入；如果没有注入；就用下面的这种注入方式
//    @Bean
//    @ConditionalOnMissingBean
//    public Classes findClassesIfNotExist(){
//        Classes classes = new Classes();
//        classes.setNumber(Integer.parseInt(users.getAge()));
//        return classes;
//    }
    @Bean
    @ConditionalOnProperty(prefix = "test.yx",name = "age",havingValue = "23")
    public Classes findClassesIfNotExist(){
        Classes classes = new Classes();
        classes.setNumber(Integer.parseInt(users.getAge()));
        return classes;
    }


}
